﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace MyAspx.Framework.WebUnit
{
    public class WebDownload
    {
        public void Down(string serverFilePath, string clientDownPath,out FileInfo zipfile)
        {
            WebClient _client = new WebClient();
            // _client.DownloadFile(txtfile.Text,@"demodownfold.zip");

            string URLAddress = serverFilePath;

            //下载到临时的目录Temp去
            string receivePath = System.IO.Path.GetTempPath() + @"myaspxcomcodezip\";
            if (!System.IO.Directory.Exists(receivePath))
            {
                System.IO.Directory.CreateDirectory(receivePath);
            }
            _client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress));
            zipfile = new FileInfo(receivePath + System.IO.Path.GetFileName(URLAddress));
            //return zipfile;
        }
        [Description("解压临时文件夹到唯一目录")]
        public void Zip(FileInfo file)
        {
            string filename = file.Name;
            filename = filename.Split('.')[0].ToString();
            string direct = file.FullName.Split('\\')[file.FullName.Split('\\').Length - 1].Split(
                '.')[0].ToString();
            string dirparent = file.FullName.Replace(file.Name,""); 
            if (!Directory.Exists(dirparent+filename) )
            {
                Directory.CreateDirectory(dirparent + filename);
            }
        }
    }
}
